package com.project.poetry.service.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.poetry.common.anno.CanOperation;
import com.project.poetry.service.entity.dto.poetry.PoetryAuthorDTO;
import com.project.poetry.service.entity.dto.poetry.PoetryDTO;
import com.project.poetry.service.entity.dto.poetry.PoetryListDTO;
import com.project.poetry.service.entity.dto.poetry.PoetryListOutDTO;
import com.project.poetry.service.service.PoetryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 诗词控制器
 * @author mengxj
 */
@Api("诗词")
@RestController
@RequestMapping("poetry")
public class PoetryController {

    @Resource
    private PoetryService poetryService;

    @ApiOperation("获取作品详情")
    @GetMapping("getPoetryDetail")
    public PoetryDTO getPoetryDetail(@RequestParam Long poetryId){
        return this.poetryService.getPoetryDetail(poetryId);
    }

    @CanOperation("保存作品")
    @ApiOperation("保存作品")
    @PostMapping("savePoetry")
    public void savePoetry(@RequestBody PoetryDTO poetry){
        this.poetryService.savePoetry(poetry);
    }

    @ApiOperation("作品列表")
    @GetMapping("poetryList")
    public IPage<PoetryListOutDTO> poetryList(PoetryListDTO poetryList){
        return this.poetryService.poetryList(poetryList);
    }

    @ApiOperation("查询有作品的作者")
    @GetMapping("poetryAuthor")
    public List<PoetryAuthorDTO> poetryAuthor(){
        return this.poetryService.poetryAuthor();
    }

    @ApiOperation("删除作品")
    @GetMapping("deleteById")
    public void deleteById(Long id){
         this.poetryService.removeById(id);
    }

}
